﻿package com.swfmessenger.utils
{

/*****************************************************************************

	Class: StringEx
	Author: Marcos Augusto Bitetti
	função: Ampliar as operações de string
			Implementado as preças, eu confesso
	
/****************************************************************************/

public class StringEx
{
	
	public function StringEx() {
		
	}
	
	static const NL:String = "\r\n";
	
	static public function trim(str:String):String {
		var isValido:Function = function (char:String):Boolean {
			var num:int = char.charCodeAt(0);
			if (num>32) return true;
			return false;
		};
		var i:int;
		//inicio
		var ini:int = 0;
		for(i=0; i<str.length; i++) if (!isValido(str.substr(i,1))) ini=i; else {
			ini = i;
			break;
		}
		//fim
		var end:int = str.length;
		for(i=str.length-1; i>=ini; i--) if (!isValido(str.substr(i,1))) end=i; else {
			break;
		}
		// ok
		//trace("TRIM: " + str.substring(ini,end));
		return str.substring(ini,end);
	}
	
}
	
}